package com.fs.uc.security;

import com.fs.uc.core.SubjectType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author 崔超
 * 2021/12/6
 */
public class AuthContext {
    private static final Logger LOGGER = LoggerFactory.getLogger(AuthContext.class);

    private static final ThreadLocal<Long> tl_subjectId = new ThreadLocal<>();
    private static final ThreadLocal<SubjectType> tl_subjectType = new ThreadLocal<>();

    public static Long getSubjectId() {
        return tl_subjectId.get();
    }

    public static void setSubjectId(Long subjectId) {
        tl_subjectId.set(subjectId);
    }

    public static SubjectType getSubjectType() {
        return tl_subjectType.get();
    }

    public static void setSubjectType(SubjectType type) {
        tl_subjectType.set(type);
    }

    public static void destroy() {
        LOGGER.info("销毁Auth上下文信息");
        tl_subjectId.remove();
        tl_subjectType.remove();
    }
}
